package com.server.modules.api.service.impl;

import com.server.common.utils.StringUtils;
import com.server.modules.api.dao.SettlementAPIDao;
import com.server.modules.api.service.ISettlementAPIService;
import com.server.modules.sys.entity.settlement.Settlement;
import com.server.modules.sys.entity.settlement.item.SettlementItem;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by Administrator on 2016/9/19.
 */
@Service
public class SettlementAPIServiceImpl implements ISettlementAPIService {

    @Autowired
    private SettlementAPIDao settlementAPIDao;


    @Override
    public Settlement getFinalPaymentDetails(String customPayId) {
        if(!StringUtils.isBlank(customPayId)){
            List<Settlement> settlements = settlementAPIDao.selectByCustomPayId(customPayId);
            Settlement settlement=null;
            for (Settlement settlement1 : settlements) {
                String type = settlement1.getType();
                if("0".equals(type)){
                    settlement=settlement1;
                }
            }
            if(settlement!=null){
                List<SettlementItem> settlementItems = settlementAPIDao.selectItemsBySettlementId(settlement.getId());
                settlement.setItems(settlementItems);
                return settlement;
            }
        }
        return null;
    }
}
